#ifndef TCP_SOCKET_H
#define TCP_SOCKET_H

#include "i_socket.h"

#include "socket/socket.h"
#include "socket/throwing_error_policy.h"
#include "socket/blocking_policy.h"
#include "socket/no_locking_policy.h"

#include <boost/shared_ptr.hpp>

typedef network::socket<
		network::blocking_policy, 
		network::no_locking_policy,
		network::throwing_error_policy
	> tcp_sock_impl;

namespace network {
	class tcp_socket : public network::i_socket {
	public:
		tcp_socket(boost::shared_ptr<tcp_sock_impl> impl):_impl(impl) {}
		tcp_socket() {_impl.reset(new tcp_sock_impl());} 
		tcp_socket(const string &addr, int port) 
		{
			_impl.reset(new tcp_sock_impl(addr, port));
		}
		virtual ~tcp_socket() {}

		virtual void send(const string &str);
		virtual string recv();

		virtual bool listen() const {return _impl->listen();}
		virtual bool bind(int port) {return _impl->bind(port);}
		virtual bool accept(tcp_socket &sock) 
		{
			return _impl->accept(*sock.get_impl());
		}

		boost::shared_ptr<tcp_sock_impl> get_impl() {return _impl;}
	private:
		boost::shared_ptr<tcp_sock_impl> _impl;
	};
}

#endif
